package net.uzen.office.article.dao;

import java.util.ArrayList;
import java.util.List;

import net.uzen.office.article.model.Article;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class ArticleDaoImpl extends SqlMapClientDaoSupport implements
		ArticleDao {

	@Override
	public int createArticle(Article article) {
		int articleNo = (Integer) getSqlMapClientTemplate().insert(
				"article.createArticle", article);
		return articleNo;
	}

	@Override
	public boolean deleteArticle(Article article) {
		int result = getSqlMapClientTemplate().delete("article.deleteArticle",
				article);
		return result > 0 ? true : false;
	}

	@Override
	public Article getArticle(Article article) {
		return (Article) getSqlMapClientTemplate().queryForObject(
				"article.getArticle", article);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Article> getArticleList(Article article) {
		return (ArrayList<Article>) getSqlMapClientTemplate().queryForList(
				"article.getArticleList", article);
	}

	@Override
	public boolean modifyArticle(Article article) {
		int result = getSqlMapClientTemplate().update("article.modifyArticle",
				article);
		return result > 0 ? true : false;
	}

	@Override
	public int getArticleOrder(Article article) {
		int articleOrder = (Integer) getSqlMapClientTemplate().queryForObject("article.getArticleOrder", article);
		return articleOrder;
	}
	
	@Override
	public boolean updateArticlesOrder(Article article) {
		int result = getSqlMapClientTemplate().update("article.updateArticlesOrder",
				article);
		return result > 0 ? true : false;		
	}
}
